"use strict";
(function(host){

var mvc = host.mvc;

var STYLESHEET = null;
function StyleSheetManage(cssNode){
	if(util.isString(cssNode)){
		cssNode = util.$(cssNode);
	}
	if(!cssNode){
		cssNode = document.createElement('style');
		cssNode.setAttribute('type', 'text/css');
		cssNode.setAttribute('ns', mvc.CONFIGURE.namespace);
	}
	document.head.appendChild(cssNode);
	this.node = cssNode;
	this.sheet = this.node.sheet;
}
StyleSheetManage.prototype = {
	enable: function(){
		this.sheet.disabled = false;
		return this;
	},
	disable: function(){
		this.sheet.disabled = true;
		return this;
	},
	add: function(name, content){
		if(util.isObject(content)){
			content = util.obj2css(content);
		}
		var idx = this.sheet.insertRule(name + '{' + (content || '') + '}', 0);
		return this.sheet.rules[idx];
	}
};
mvc.addGlobalStyle = function(type, value, cssObject, noPrefix){
	if(!noPrefix){
		type = mvc.prefixed(type);
	}
	if(value){
		type = type + '="' + value + '"';
	}
	type = '[' + type + ']';
	STYLESHEET.add(type, cssObject);

	return this;
};
mvc.addGlobalRule = function(selector, cssObject){
	return STYLESHEET.add(selector, cssObject);
};

mvc.createRule = function(selector){
	return STYLESHEET.add(selector, cssObject);
};

mvc.setTypebsolute = function(type){
	if(util.isString(type)){
		return this.addGlobalStyle('type', type, this.setTypebsolute.$CSS$);
	} else if(util.isArray(type)){
		type.forEach(function(t){
			mvc.setTypebsolute(t);
		});
	}
	return this;
};
mvc.setTypebsolute.$CSS$ = {
	'position': 'absolute',
	'background-size': '100% 100%',
	'background-repeat': 'no-repeat',
};


mvc.init = function(){
	if(STYLESHEET) return;
	STYLESHEET = new StyleSheetManage();
	// var uiType = (
	// 	CONFIGURE.prefix 
	// 	? CONFIGURE.prefix + '-'
	// 	: ''
	// 	) + 'type';
	// var globalCssSelector = '[ns="' + CONFIGURE.namespace + '"]';

	this
	// .addGlobalStyle('ns', CONFIGURE.namespace, {
	// 	'position': 'absolute',
	// 	'background-size': '100% 100%',
	// 	'background-repeat': 'no-repeat'
	// }, 1)
	.setTypebsolute(['type', 'dragable'])
	.addGlobalStyle('type', 'move', {
		'position': 'absolute',
		'left': 0,
		'right': 0,
		'top': 0,
		'bottom': 0
	})
	.addGlobalStyle('type', 'resize', {
		'position': 'absolute',
		'left': 'auto',
		'right': 0,
		'top': 'auto',
		'bottom': 0,
		'width': 10,
		'height': 10,
		'background-color': 'rgba(0,0,0,0.8)'
	})
	;
};

})(window);